//app.js
var util=require('utils/util.js');
App({
  globalData: {
    openid: null
  },
  onLaunch: function () {
    var openid = wx.getStorageSync('openid');
    if(openid){
      this.globalData.openid=openid
    }else{
      var that=this
      wx.login({
        success (res) {
          if (res.code) {
            wx.request({
              url: util.baseUrl+'user/Instll/index',
              data: {code:res.code},
              success:function(res){
                if(res.data.code==-1){
                    wx.showToast({
                      title: res.data.msg,
                      icon:'none'
                    })
                  }
                  if(res.data.code==0){
                    wx.setStorageSync('openid', res.data.data.openid);
                    that.globalData.openid=res.data.data.openid
                    console.log(res.data)
                  }
              },
              fail:function(res){
                wx.showToast({
                  title: '请求失败',
                  icon:'none'
                })
              }
            })
          } else {
            console.log('登录失败！' + res.errMsg)
          }
        }
      })
    }
  }
})